package algorithm.leetcode.array;

import java.io.IOException;
import java.util.*;

/**
 * 旋转数组
 */
public class RotateArray {

    /**
     *    原来的数组: [1,2,3,4,5,6,7]
     * 向右轮转 1 步: [7,1,2,3,4,5,6]
     * 向右轮转 2 步: [6,7,1,2,3,4,5]
     * 向右轮转 3 步: [5,6,7,1,2,3,4]
     * @param nums
     * @param k
     */
    public void rotate(int[] nums, int k) {
        int len = nums.length;
        int[] arr = new int[len];
        for(int i=0; i<len; i++) {
            arr[(i+k) % len] = nums[i];
        }
        System.arraycopy(arr, 0, nums, 0 , len);
    }



    public static void main(String[] args) {
        String s = "hello";
        String s1 = new String("hello");
        String s2 = s1.intern();
        System.out.println(s == s1);
        System.out.println(s1 == s2);
        System.out.println(s == s2);
//        new RotateArray().rotate(new int[]{1,2,3,4,5,6,7}, 0);
//        new RotateArray().rotate(new int[]{1,2}, 3);
    }
}
